<template>
	<view class="container">
		<view class="header"></view>
		<view class="content">
			<!-- 这里是可滚动的内容 -->
			<scroll-view class="scroll-view"  @scrolltolower="scrolltolowerFn" scroll-y>
				<view class="scroll-view-inner"> <!-- 内容区域 -->
					<view class="card" v-for="(item,index) in dataList" :key="index">
						<view class="title-content">
							<view style="display: flex;padding: 20rpx 20rpx 0 20rpx; justify-content: space-between;">
								<view class="title">
									订单号{{item.orderNo}}
								</view>
								<view class="title-c" style="padding: 10rpx;border-radius: 8rpx;color: #201b8c;">
									ID:{{item.id}}
								</view>
							</view>
							<view style="border-bottom: 1px solid #f6f6f6;margin: 20rpx;"></view>
							<view class="column" style="display: flex;justify-content: space-between;">
								<view class="font-weight-content">
									{{item.nickName}}|{{item.uid}}
								</view>
								<!-- <view class="font-weight-content">
									{{closingDetail.amount}}元
								</view> -->
							</view>
							<view style="display: flex;padding: 20rpx;justify-content: space-between;">
								<view class="title">
									交易类型
								</view>
								<view class="title-c">
									{{pmType[item.pm]}}
								</view>
							</view>

							<view style="display: flex;padding: 20rpx;justify-content: space-between;">
								<view class="title">
									金额
								</view>
								<view class="title-c" style="color: #201b8c;">
									<span v-if="item.pm == 0">-</span>{{item.amount}}
								</view>
							</view>
							<view style="display: flex;padding: 20rpx;justify-content: space-between;">
								<view class="title" style="width: 150rpx;">
									备注
								</view>
								<view class="title-c">
									{{item.mark}}
								</view>
							</view>
							<view style="display: flex;padding: 20rpx;justify-content: space-between;">
								<view class="title">
									交易时间
								</view>
								<view class="title-c">
									{{item.createTime}}
								</view>
							</view>
							<view style="border-bottom: 1px solid #f6f6f6;margin: 20rpx;"></view>
						</view>
					</view>
				</view>
				<u-empty v-if="!dataList.length" style="background-color: #fff;height: 100vh;" mode="data"
					icon="http://cdn.uviewui.com/uview/empty/data.png"></u-empty>
				<!-- 上拉加载更多 -->
				<uni-load-more v-else :status="loadMoreStatus"></uni-load-more>
			</scroll-view>
		</view>
	</view>
</template>
<script>
	import {
		getFundsFlowApi
	} from '@/api/finance.js';
	import {
		setThemeColor
	} from '../../../utils/setTheme';
	let app = getApp();
	export default {
		data() {
			return {
				bgColor: "#ffffff",
				theme: app.globalData.theme,
				cancellForm: {
					page: 1,
					limit: 10,
				},
				dataList: [],
				totalPage: 1,
				loadMoreStatus: 'noMore',
				pmType: {
					0: '订单退款',
					1: '订单支付',
				}
			};
		},
		onLoad() {
			this.bgColor = setThemeColor()
			uni.setNavigationBarColor({
				frontColor: '#ffffff',
				backgroundColor: this.bgColor,
			});
		},
		created() {
			this.initData();
		},
		methods: {
			initData() {
				// 首次激活时被调用
				this.cancellForm.page = 1;
				this.loadMoreStatus = 'more';

				this.getFundsFlowList();
			},
			// 触底事件 onReachBottom 加载更多数据
			scrolltolowerFn() {
				if (this.loadMoreStatus != 'more') {
					return;
				};
				this.cancellForm.page++;
				this.getFundsFlowList(true);
			},
			onrefresh(e) {
				this.refreshing = true;
				this.refreshText = "刷新中...";
				setTimeout(() => {
					this.refreshing = false;
					this.refreshFlag = false;
					this.refreshText = "已刷新";
				}, 2000)
			},
			onpullingdown(e) {
				if (this.refreshing) {
					return;
				}
				this.pulling = false;
				if (Math.abs(e.pullingDistance) > Math.abs(e.viewHeight)) {
					this.refreshFlag = true;
					this.refreshText = "释放立即刷新";
				} else {
					this.refreshFlag = false;
					this.refreshText = "下拉可以刷新";
				}
			},
			// --------api------获取数据
			getFundsFlowList(isMerge) {
				let that = this;
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				if (!isMerge) {
					this.cancellForm.page = 1;
					this.loadMoreStatus = 'more';
				};
				getFundsFlowApi(this.cancellForm).then((res) => {
					let data = res.data;
					if (isMerge) {
						that.$util.SplitArray(data.list, that.dataList);
					} else {
						that.dataList = data.list;
					}
					that.totalPage = data.totalPage;
					if (data.totalPage == this.cancellForm.page) {
						that.loadMoreStatus = 'noMore';
					}
					uni.hideLoading();
				})
			},
		}
	}
</script>
<style lang="scss">
	page {
		height: 100%;


	}

	.container {
		display: flex;
		flex-direction: column;
		height: 100%;
	}

	.header {
		// height: 100px;
		// background-color: lightblue;
	}

	.content {
		flex: 1;
		overflow: hidden;
	}

	.scroll-view {
		height: 100%;
	}

	.scroll-view-inner {
		/* 根据实际情况设置高度 */
		// display: flex;
		// flex-direction: column;

		/* 内容区域背景色 */
	.card {
		background-color: #fff;
		margin: 20rpx;
		border-radius: 10rpx;
	}
	
	.font-weight-content {
		font-weight: bold;
	}
	
	.column {
		padding: 20rpx;
		display: flex;
		flex-flow: row;
		text-align: center;
		justify-content: space-between;
	
		.title {
			display: flex;
			// flex: 1;
			width: 150rpx;
		}
	
		.title-c {
			display: flex;
			flex: 1;
			justify-content: left;
			// padding-left: 20rpx;
		}
	}
	}
	
</style>